package cn.tedu.boot332.controller;

import cn.tedu.boot332.entity.Hero;
import cn.tedu.boot332.mapper.HeroMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Statement;
import java.util.List;

@RestController
public class HeroController {

    @Autowired(required = false)
    HeroMapper mapper;

    @RequestMapping("/add")
    public String add(Hero hero){
        mapper.insert(hero);
        return "添加成功";
    }
    @RequestMapping("/select")
    public String select(){
        List<Hero> list=mapper.select();
        String html="<table border=\"1\">";
        html+="<caption>英雄列表</caption>";
        html+="<tr><th>id</th><th>名字</th><th>类型</th><th>小金库</th></tr>";
        for (Hero h:list) {
            html+="<tr>";
            html+="<td>"+h.getId()+"</td>";
            html+="<td>"+h.getName()+"</td>";
            html+="<td>"+h.getType()+"</td>";
            html+="<td>"+h.getMoney()+"</td>";
            html+="</tr>";
        }
        html+="</table>";
        return html;
    }
}
